package com.lbd.gulimall.product.web;

import com.lbd.gulimall.product.service.ItemService;
import com.lbd.gulimall.product.vo.item.SkuItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.concurrent.ExecutionException;

/**
 * @Author: linbd
 * @Description:
 * @Date: 2023/3/7 22:28
 */
@Controller
public class ItemController {
    @Autowired
    private ItemService itemService;

    @RequestMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) {
        SkuItemVO skuItemVO = null;
        try {
            skuItemVO = itemService.getSkuItem(skuId);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        model.addAttribute("item", skuItemVO);
        return "item";
    }
}
